import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

def plot_graph():

    # 创建Matplotlib图形和轴
    fig, ax = plt.subplots()

    # 绘制一些数据
    x = [1, 2, 3, 4, 5]
    y = [1, 4, 7, 3, 9]
    ax.plot(x, y)

    # 创建包含Matplotlib图形的Tkinter画布
    canvas = FigureCanvasTkAgg(fig, master=frame)
    canvas.draw()

    # 将画布添加到Tkinter框架中
    canvas.get_tk_widget().pack()

# 创建Tkinter窗口
root = tk.Tk()

# 创建Tkinter框架以容纳Matplotlib图形
frame = tk.Frame(root)
frame.pack()

# 创建Tkinter按钮以触发Matplotlib图形的创建
button = tk.Button(root, text="绘制图表", command=plot_graph)
button.pack()

# 启动Tkinter事件循环
root.mainloop()

# 文件对话框的本质是得到文件的路径，在底层其实也就是得到了文件的存储地址 